package client;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;
import javax.swing.plaf.metal.MetalBorders;


public class SchwimmenLogin extends JFrame implements ActionListener
{
	JButton newUser;
	JButton regUser;
	JButton newUserLogin;
	JButton regUserLogin;
	JPanel left;
	JPanel leftNew;
	JPanel leftReg;
	
	public SchwimmenLogin ()
	{
		this.getContentPane().setBackground(Color.WHITE);
		this.getContentPane().setLayout(new BoxLayout(this.getContentPane(), BoxLayout.X_AXIS));
		this.addComponents(this.getContentPane());
		this.setSize(400,200);
		this.setVisible(true);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	
	public void addComponents(Container c)
	{
		JPanel login = new JPanel();
		login.setLayout(new CardLayout());
		
		//Initial login screen
		left = new JPanel();
		left.setBackground(Color.WHITE);
		left.setLayout(new BoxLayout(left, BoxLayout.Y_AXIS));
		newUser = new JButton("New User");
		newUser.setAlignmentX(Component.CENTER_ALIGNMENT);
		newUser.addActionListener(this);
		regUser = new JButton("Registered User");
		regUser.setAlignmentX(Component.CENTER_ALIGNMENT);
		regUser.addActionListener(this);

		left.add(newUser);
		left.add(Box.createRigidArea(new Dimension(0,20)));
		left.add(Box.createRigidArea(new Dimension(0,20)));
		left.add(regUser);
		
		JPanel right = new JPanel();
		right.setBackground(Color.WHITE);
		right.setLayout(new BoxLayout(right, BoxLayout.Y_AXIS));
		JLabel topthree = new JLabel("Top 3 Players");
		topthree.setAlignmentX(Component.CENTER_ALIGNMENT);
		JTextArea ta = new JTextArea();
		ta.setMinimumSize(new Dimension(200, 100));
		ta.setEditable(false);
		ta.setBorder(MetalBorders.getTextFieldBorder());
		right.add(topthree);
		right.add(ta);
		
		newUserLogin = new JButton("Login");
		newUserLogin.setAlignmentX(Component.CENTER_ALIGNMENT);
		newUserLogin.addActionListener(this);
		regUserLogin = new JButton("Login");
		regUserLogin.setAlignmentX(Component.CENTER_ALIGNMENT);
		regUserLogin.addActionListener(this);
		
		//New user section
		leftNew = new JPanel();
		leftNew.setBackground(Color.WHITE);
		leftNew.setLayout(new BoxLayout(leftNew, BoxLayout.Y_AXIS));
		JLabel newUserMsg = new JLabel("Enter your new username:");
		newUserMsg.setAlignmentX(Component.CENTER_ALIGNMENT);
		JTextField newUsername = new JTextField();
		newUsername.setMaximumSize(new Dimension(200, 25));
		JLabel newPass = new JLabel("Enter your new password:");
		newPass.setAlignmentX(Component.CENTER_ALIGNMENT);
		JTextField newUserPass = new JTextField();
		newUserPass.setMaximumSize(new Dimension(200, 25));
		JLabel error = new JLabel("");
		
		leftNew.add(newUserMsg);
		leftNew.add(newUsername);
		leftNew.add(newPass);
		leftNew.add(newUserPass);
		leftNew.add(error);
		leftNew.add(newUserLogin);
		
		
		//Reg user section
		leftReg = new JPanel();
		leftReg.setBackground(Color.WHITE);
		leftReg.setLayout(new BoxLayout(leftReg, BoxLayout.Y_AXIS));
		JLabel regUserMsg = new JLabel("Enter your username:");
		regUserMsg.setAlignmentX(Component.CENTER_ALIGNMENT);
		JTextField regUsername = new JTextField();
		regUsername.setMaximumSize(new Dimension(200, 25));
		JLabel regPass = new JLabel("Enter your password:");
		regPass.setAlignmentX(Component.CENTER_ALIGNMENT);
		JTextField regUserPass = new JTextField();
		regUserPass.setMaximumSize(new Dimension(200, 25));
		
		leftReg.add(regUserMsg);
		leftReg.add(regUsername);
		leftReg.add(regPass);
		leftReg.add(regUserPass);
		leftReg.add(error);
		leftReg.add(regUserLogin);
		
		login.add(left, "Login");
		login.add(leftNew, "New User Login");
		login.add(leftReg, "Reg User Login");
		c.add(login);
		c.add(Box.createRigidArea(new Dimension(20,0)));
		c.add(right);
	}
	
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource() == this.newUser)
		{
			//change to other screen
			left.setVisible(false);
			leftNew.setVisible(true);
		}
		if(e.getSource() == this.regUser)
		{
			//change to other screen
			left.setVisible(false);
			leftReg.setVisible(true);
		}
		if(e.getSource() == newUserLogin)
		{
			//Verify then login
			this.setVisible(false);
		}
		if(e.getSource() == regUserLogin)
		{
			//Verify username/password
			this.setVisible(false);
		}
	}
	
	public static void main(String args[])
	{
		SchwimmenLogin sl = new SchwimmenLogin();
	}
}